home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / pctj8404.arc / SEARCH2.BAS < prev    next >
BASIC Source File  |  1986-09-14  |  896b  |  32 lines

  1. '$$$$$$$$$$$$$$ 
  2. 'Subroutine 
  3. '$$$$$$$$$$$$$$ 
  4. '    This is the modified sequential search subroutine. 
  5. '    Input is the table in which to look up (ITABLE), 
  6. '    the number of entries in the table (NTABLE), and 
  7. '    the number whose index is to be found (JKEY).  
  8. '    Output is the index (INDX) such that  
  9. '    TABLE(INDX) = JKEY 
  10. '    MODIFIED SEQUENTIAL SEARCH 
  11. 8000 rem Start. 
  12. REM CMP   cmp = 0 
  13.      for i. = 11 to ntable+10 step 10 
  14. REM CMP     cmp = cmp + 1. 
  15.        if (ntable <= i.) then goto 8010 
  16.        if (itable(i.) < jkey) then goto 8020 
  17. '    ITABLE(i.) < jkey; go back and look through last 10 entries. 
  18. 8010   jstart. = i.-10 
  19.        for j. = jstart. to i. 
  20. REM CMP       cmp = cmp + 1. 
  21.          if (itable(j.) = jkey) then indx=j.: return 
  22.        next j. 
  23. 8020 next i. 
  24.      return 
  25.